﻿using System.Web.Mvc;

namespace CodeContrib.Web.Mvc
{
	public class DateAndTimeAttribute : CustomModelBinderAttribute
	{
		private readonly IModelBinder _binder;

		// The user cares about a full date structure and full time structure, or one or the other.
		public DateAndTimeAttribute(string dateKey, string timeKey)
		{
			_binder = new DateAndTimeModelBinder
				          {
					          DateKey = dateKey,
					          TimeKey = timeKey
				          };
		}

		// The user wants to capture the date and time (or only one) as individual portions.
		public DateAndTimeAttribute(string yearKey, string monthKey, string dayKey, string hourKey, string minuteKey, string secondKey)
		{
			_binder = new DateAndTimeModelBinder
				          {
					          DayKey = dayKey,
					          MonthKey = monthKey,
					          YearKey = yearKey,
					          HourKey = hourKey,
					          MinuteKey = minuteKey,
					          SecondKey = secondKey
				          };
		}

		// The user wants to capture the date and time (or only one)
		// as individual portions.
		public DateAndTimeAttribute(string dateKey, string timeKey, string yearKey, string monthKey, string dayKey, string hourKey, string minuteKey, string secondKey)
		{
			_binder = new DateAndTimeModelBinder
				          {
					          DayKey = dayKey,
					          MonthKey = monthKey,
					          YearKey = yearKey,
					          HourKey = hourKey,
					          MinuteKey = minuteKey,
					          SecondKey = secondKey,
					          DateKey = dateKey,
					          TimeKey = timeKey
				          };
		}

		public override IModelBinder GetBinder()
		{
			return _binder;
		}
	}
}